package com.qezhhnjy.mall.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.product.ProductAttrValue;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.product.service.ProductAttrValueService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * spu属性值 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "spu属性值接口")
@Slf4j
@RequestMapping("/product-attr-value")
public class ProductAttrValueController {
    @Resource
    private ProductAttrValueService productAttrValueService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取spu属性值信息")
    public BaseResult<ProductAttrValue> get(Long id) {
        ProductAttrValue productAttrValue = productAttrValueService.getById(id);
        return BaseResult.success(productAttrValue);
    }

    @PostMapping("/save")
    @Operation(summary = "新增spu属性值信息")
    public BaseResult<ProductAttrValue> save(@RequestBody ProductAttrValue productAttrValue) {
        productAttrValueService.save(productAttrValue);
        return BaseResult.success(productAttrValue);
    }

    @PutMapping("/update")
    @Operation(summary = "更新spu属性值信息")
    public BaseResult<ProductAttrValue> update(@RequestBody ProductAttrValue productAttrValue) {
        productAttrValueService.updateById(productAttrValue);
        return BaseResult.success(productAttrValue);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取spu属性值信息")
    public BaseResult<Page<ProductAttrValue>> page(@RequestBody Page<ProductAttrValue> page) {
        productAttrValueService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除spu属性值信息")
    public BaseResult<Long> delete(Long id) {
        productAttrValueService.removeById(id);
        return BaseResult.success(id);
    }
}

